package eco2automotive.gui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import eco2automotive.port.*;
import eco2automotive.gui.components.*;
import eco2automotive.gui.actions.Act_btn_PORT_SELECT;

/**  
  * * Show a modal dialog: select a availabe port for the comunication
 *  with the interface control
  * @version 1.0
  * @autor Fco. Javier Sánchez Esparza
  * @see eco2automotive.gui.components.Panel_PORT_FINDER
  * @see eco2automotive.gui.components.Panel_PORT_INFO
 *  @see eco2automotive.port.Connection
  *
  */ 
public class Layout_PORT_SELECTION extends JDialog{ 
   Connection CONN;
   JButton btn_PORT_SELECT;
   JButton btnGo;
   JFrame parent;  
   Panel_PORT_INFO PORT_INFO;
   Panel_PORT_FINDER PORT_FINDER;
   
   /** 
     * Create and add a new Panel_PORT_INFO, Panel_PORT_FINDER to the 
    *  JDialog window
     * @param j is the root JFrame
     * @param CONN is a Connection object
    *  @see eco2automotive.port.Connection     
    */        
 
  public Layout_PORT_SELECTION(JFrame j,Connection CONN){  
      this.setModal(true);
      this.setTitle("Firs selection...");    
      this.CONN=CONN;            
      PORT_INFO=new Panel_PORT_INFO(CONN);      
      PORT_FINDER=new Panel_PORT_FINDER();
      btn_PORT_SELECT = new JButton("Select");    
      btn_PORT_SELECT.addActionListener(new Act_btn_PORT_SELECT(CONN,PORT_FINDER,PORT_INFO));
      btnGo= new JButton("GO!");   
      btnGo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
    Layout_PORT_SELECTION.this.dispose();
}
        });
            
    setLayout(new BorderLayout());
    JPanel south= new JPanel();
    south.setLayout(new FlowLayout()/*new BoxLayout(south, BoxLayout.X_AXIS)*/);    
    south.add(btn_PORT_SELECT);    
    south.add(btnGo);
    
    JPanel center= new JPanel();
    center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));    
    center.add(PORT_INFO);
    center.add(PORT_FINDER);
    
    this.add(center,BorderLayout.CENTER);
    this.add(south,BorderLayout.SOUTH);
      this.setModal(true);      
      this.pack();
 
      
  }
   
   
}
